package com.psp.park.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.park.controller.res.*;
import com.psp.park.controller.res.bean.*;
import com.psp.park.controller.springmvc.req.*;

/**
 * 管理用户-账户相关接口
 **/
@Controller
@RequestMapping(value = "/park/visitor", produces = "application/json")
public class SVisitorController {
	@Autowired
	com.psp.park.controller.VisitorController visitorController;

	/**
	 * 辅助来访用户注册
	 **/
	@RequestMapping("/v1/register")
	@ResponseBody
	public BaseResult register(@Validated RegisterParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return visitorController.register(param, request, response);
	}

	/**
	 * 获取辅助来访用户列表
	 **/
	@RequestMapping("/v1/list")
	@ResponseBody
	public ListResult<RVisiterBean> list(@Validated GetUserListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RVisiterBean> res = new ListResult<RVisiterBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return visitorController.list(param, request, response);
	}

	/**
	 * 发送手机验证码
	 **/
	@RequestMapping("/v1/sendPhoneCode")
	@ResponseBody
	public BaseResult sendPhoneCode(@Validated SendPhoneCodeParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return visitorController.sendPhoneCode(param, request, response);
	}
}
